<script setup>

import getDate from "@/utils/dateChange.js";
import router from "@/router/index.js";
import {ref} from "vue";
import useLoginStore from "@/stores/user/index.js";

const loginStore = useLoginStore();

//接受数据
const props = defineProps(
    {
      articleList: {
        type: {},
        default: () => ({})
      },
      activeName: {
        type: String,
        default: "all"
      },
      searchParam: {
        type: String,
        default: ""
      }
    }
);

loginStore.type = props.activeName
loginStore.searchParam = props.searchParam

//定义分页器
const page = ref(1)
const size = ref(10)

//size大小切换
const handleSizeChange = () => {
  loginStore.personAllOrCollectWorkAction(page.value, size.value, loginStore.type, loginStore.searchParam)
}

//当前页切换
const handleCurrentChange = () => {
  loginStore.personAllOrCollectWorkAction(page.value, size.value, loginStore.type, loginStore.searchParam)
}


//文章详情
const detailNews = async (value) => {
  await router.push({
    path: '/detail',
    query: {
      id: value
    }
  })
}

</script>

<template>
  <div class="article-list">

    <div class="article" v-for="(item, index) in articleList.records">
      <div class="left-article" @click="detailNews(item.id)">
        <p class="title">{{ item.title }}</p>
        <ul class="desc-info">
          <li>{{ item.labels }}</li>
          <li>{{ item.commentCount }}评论</li>
          <li>{{ getDate(item.createTime) }}</li>
        </ul>
      </div>
      <div class="right-article" @click="detailNews(item.id)">
        <img :src="item.images"/>
      </div>
    </div>


    <!-- 分页器      -->
    <el-pagination
        v-model:current-page="page"
        v-model:page-size="size"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="articleList.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
  </div>


</template>

<style scoped lang="less">


.article {
  box-sizing: border-box;
  padding: 16px 0;
  height: 144px;
  display: flex;
  justify-content: space-between;


  .right-article {
    margin-left: 18px;

    img {
      width: 156px;
      height: 104px;
    }
  }

  .desc-info {
    margin-top: 58px;
    display: flex;

    li {
      font-size: 14px;
      color: #999;
    }

    li:nth-child(2) {
      margin-left: 15px;
    }

    li:nth-child(3) {
      margin-left: 15px;
    }
  }

  .left-article {
    display: flex;
    flex-direction: column;
    cursor: pointer;


    .desc-info {
      margin-top: 58px;
      display: flex;

      li {
        font-size: 14px;
        color: #999;
      }

      li:nth-child(2) {
        margin-left: 15px;
      }

      li:nth-child(3) {
        margin-left: 15px;
      }
    }


    &:hover {
      color: #f04142;
    }
  }
}
</style>